package com.onesports.intelligent.k12.polarlight.controller.wx.cls;

import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.cls.ClassExitDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.course.DisbandClassDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.wx.CoachEvaluateDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.cls.ClassWxDetailVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.cls.ClassWxPageVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.wx.CoachEvaluateVO;
import com.onesports.intelligent.k12.polarlight.service.grade.ClassInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;
import java.util.List;

/**
 * @author FPH
 * @since 2022年7月15日15:25:26
 */
@RestController
@RequestMapping(ApiPathConstants.WX_USER_ClS)
@RequiredArgsConstructor
@Api(tags = "会员端-班级")
@PreAuthorize("hasAuthority('MINI_APP')")
public class ClassWxController {
    private final ClassInfoService classInfoService;

    @GetMapping("page")
    @ApiOperation("获取班级列表")
    public ResponseEntity<List<ClassWxPageVO>> getWxClassPage(){
        return ResultUtil.success(classInfoService.getWxClassList(false)) ;
    }

    @GetMapping("detail")
    @ApiOperation("获取班级详情")
    public ResponseEntity<ClassWxDetailVO> getWxClassDetail(String classId){
        return ResultUtil.success(classInfoService.getWxClassDetail(classId,false)) ;
    }

    @GetMapping("mien")
    @ApiOperation("班级风采")
    public ResponseEntity<ClassWxDetailVO> getMien(String classId){
        return ResultUtil.success(classInfoService.getMienByClass(classId)) ;
    }

    @PostMapping("exit")
    @ApiOperation("退出班级（家长）")
    public ResponseEntity<String> exitClass(@RequestBody @Valid ClassExitDTO classExitDTO) throws ParseException {
        return classInfoService.exitClass(classExitDTO.getClassId(),classExitDTO.getStudentList())
                ?ResultUtil.success("退出成功"):ResultUtil.success("退出失败");
    }

    @GetMapping("get-evaluate")
    @ApiOperation("获取教练对学员的评价")
    public ResponseEntity<CoachEvaluateVO> getEvaluate(@Valid CoachEvaluateDTO dto){
        return ResultUtil.success(classInfoService.getEvaluate(dto)) ;
    }

    @PostMapping("disband-class")
    @ApiOperation("解散拼班(团长)")
    public ResponseEntity<String> disbandClass(@RequestBody DisbandClassDTO disbandClassDTO) {
        classInfoService.disbandClass(disbandClassDTO);
        return ResultUtil.success("解散成功");
    }

}
